20.1 Generic IRQ Subsystem
The Generic IRQ Subsystem (Generic IRQ Chip Framework) is a critical abstraction layer within the Linux kernel designed to isolate the hardware details of low-level interrupt controllers from upper-level device drivers. Acting as the core framework for the unified management of various hardware interrupts across the kernel, it abstracts the discrepancies between different architectures and interrupt controllers so that driver developers do not need to manage low-level hardware specificities. Its existence solves a significant engineering bottleneck: the hardware layout of interrupt controllers across different CPU architectures (such as x86, ARM, and RISC-V) varies drastically, and if every device driver required hard-coded interrupt logic tailored to specific hardware, the codebase would become unmaintainable. Through the generic IRQ subsystem, the Linux kernel provides a set of completely hardware-independent interfaces.
The generic IRQ subsystem partitions interrupt processing into the following three abstraction layers:
| Layer | Responsibility | Key Components / Functions |
|---|---|---|
| Generic Logic Layer | Maintains interrupt states and provides a unified interface to device drivers. | request_irq, disable_irq |
| Flow Control Layer | Handles distinct electrical trigger modalities (e.g., edge or level triggers). | handle_edge_irq, handle_level_irq |
| Hardware Driver Layer | Directly manipulates low-level hardware registers.“struct irq_chip |
The Generic Logic Layer (also designated as the high-level driver interface layer) provides unified interfaces such as request_irq, free_irq, enable_irq(), and disable_irq() to device drivers. Driver developers can utilize these routines without needing to track which explicit interrupt controller is running underneath.
The Flow Control Layer (high-level interrupt flow handling layer) manages the generic logic associated with distinct categories of electrical triggers (such as level-triggered or edge-triggered interrupts). Routines commonly utilized here include handle_level_irq, handle_edge_irq, and handle_fasteoi_irq.
The Chip-Level Hardware Encapsulation Layer (low-level layer) interfaces directly with the physical hardware components. It encapsulates low-level hardware operations—including masking (mask), acknowledgment (ack), and unmasking (unmask)—via the struct irq_chip structure.
The hierarchical relationship mapping out the interactions among device drivers, the generic IRQ subsystem, interrupt controller drivers, and the physical interrupt controller hardware is illustrated in Figure 20-1.
Figure 20-1 Relationships Between Device Drivers and the Functional Modules of the Generic IRQ Subsystem
During its initialization phase (typically within its xx_probe function), a device driver invokes request_irq() to register an interrupt handler, and calls free_irq() upon termination to release the consumed resources. The interrupt controller driver must register its primary interrupt service routines, which assume responsibility for executing explicit hardware operations. The core generic IRQ subsystem layer is supplied directly by the Linux kernel.
When a device driver registers an interrupt handler via request_irq(), it invokes the interface in the following manner: request_irq(irq, handler, irq_flags, name, dev). These five parameters function as an "interrupt service application form" submitted to the Linux kernel. The analytical meaning of each individual parameter encompasses:
-
irq:
The logical software interrupt number. This identifier is typically parsed dynamically from the device tree or platform data structures and cannot be arbitrarily assigned. -
handler:
A pointer referencing the primary interrupt service routine. The moment a hardware signaling event triggers, the kernel instantly branches execution to this targeted callback function. -
irq_flags:
Interrupt orchestration flags. They instruct the subsystem whether the incoming electrical signal should be evaluated as level-triggered versus edge-triggered, or define sharing behaviors. -
name:
A string descriptor mapping out the functional identity of the interrupt. Whenever an administrator executes the command cat /proc/interrupts in a terminal, this name populates the tracking column. -
dev:
A private context pointer passed straight into the interrupt handler function (acting as a tracking Cookie). Because the service routine frequently requires real-time knowledge of device register maps and operational states, passing the base device structure pointer enables the handler to access those metrics directly. Device driver engineers merely need to master this top-level functional interface to fully leverage the capabilities of the underlying interrupt controller.
Drivers can alternative invoke registration via devm_request_irq(). Within this managed interface, the first parameter points explicitly to the struct device object instantiating the interrupt, while the remaining parameters mirror the arguments passed to request_irq().
The structural internal execution flowchart governing request_irq() is detailed in Figure 20-2.
Figure 20-2 Internal Workflow of the Interrupt Subsystem
Whenever a physical hardware interrupt triggers, the operating system manages and processes the signal across the following sequential execution phases:
-
The CPU core executes a low-level hardware response, suspending the active runtime task to drop straight into the architecture-specific exception handling vector entry point.
-
The exception tracking routine routes control to invoke the generic subsystem's desc->handle_irq() handler to perform high-level flow control tracking (such as asserting a hardware ACK or masking out the line).
-
The engine executes the concrete interrupt service routines registered by the active device drivers.
-
The system can leverage request_threaded_irq() to delegate heavy, long-running processing logic out to dedicated background kernel threads (kthreads), which drastically minimizes the time windows spent running with local interrupts disabled and elevates hard real-time system responsiveness.
This execution tracking sequence can be further broken down into granular structural steps:
-
The CPU hits an exception vector, handing immediate execution control off to architecture-specific code blocks.
-
The architecture code directs the execution flow into the generic interrupt entry funnel, calling handle_irq_desc(desc).
-
The funnel triggers the high-level interrupt flow handling callback preserved inside the master interrupt descriptor (desc->handle_irq).
generic_handle_irq(unsigned int irq)-> generic_handle_irq_desc(desc)-> desc->handle_irq(desc)
Taking an i.MX6Solo system (comprising an ARM Cortex-A9 core paired with a GICv2 controller) as a concrete platform example, we can chart the complete processing pipeline from raw hardware signal down through irq-gic.c and back up into the generic framework. When a peripheral component asserts an interrupt, the functional call path is executed as follows:
-
The peripheral hardware component asserts a physical interrupt signal line.
-
The Generic Interrupt Controller (GIC) hardware propagates the interrupt signal up to the active CPU core.
-
The CPU core registers a hardware exception and drops into its architecture interrupt vector.
-
The hardware exceptions handler execution block triggers the vector handler irq_handler (hosted within the assembly file git/arch/arm/kernel/entry-armv.S) and subsequently branches execution over to gic_handle_irq() (hosted within the architecture file git/arch/arm/kernel/irq-gic-v3.c or its v2 equivalent).
-
gic_handle_irq() calls handle_domain_irq(), which interfaces with the active irq_domain mapping layer to translate the low-level physical hardware interrupt ID into a logical software interrupt number recognized by the Linux kernel.
-
The system calls generic_handle_irq(). This routine invokes irq_to_desc() to resolve the global struct irq_desc descriptor mapping to that software interrupt number; if required, it evaluates irq_desc_get_irq_data() to extract the private controller data managed by the driver.
-
generic_handle_irq() hands over control to generic_handle_irq_desc().
-
generic_handle_irq_desc(desc) fires the callback function referenced by the handle_irq field within that specific irq_desc data structure.
The handle_irq pointer targets the flow control layer's core interrupt handlers, selecting from seven predefined helper functions—including handle_level_irq(), handle_edge_irq(), and handle_fasteoi_irq()—to match the exact electrical configuration (such as level-triggered or edge-triggered lines) of the active interrupt. The execution boundary at generic_handle_irq_desc marks the definitive dividing line separating the architecture-dependent hardware layers from the high-level flow control frameworks.
-
The flow control routine calls handle_irq_event(), which physically executes the specific driver handlers (action->handler) registered across the active sharing chain. This execution path represents the explicit interface boundary separating the high-level interrupt flow control layer from the peripheral device driver layers. This function is declared within the source file git/kernel/irq/handle.c.
-
The CPU core processes the custom callback logic implemented inside the driver's registered handler().
In essence, the Linux Generic IRQ Subsystem serves as a robust abstraction layer engineered to decouple low-level hardware interrupt controllers from high-level device driver handlers. By orchestrating a unified tracking architecture built upon the interaction models of irq_desc, irq_chip, and irq_domain frameworks, it provides an expandable, cross-architecture, shareable, and fully SMP-aware unified interrupt management framework.